package com.xagcdx.group1.utils;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebFilter(value={"/*"},initParams={@WebInitParam(name="charset" ,value="utf-8")} )
public class CharacterEncoding implements Filter {
	private String character;
	public void init(FilterConfig filterConfig) throws ServletException {
		// TODO Auto-generated method stub
		
		this.character=filterConfig.getInitParameter("charset");
	}

	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
			throws IOException, ServletException {
		// TODO Auto-generated method stub
		
		if(this.character!=null){
			HttpServletRequest req=(HttpServletRequest)request;
			HttpServletResponse resp=(HttpServletResponse)response;
			req.setCharacterEncoding(this.character);
			resp.setCharacterEncoding(this.character);
			resp.setContentType("text/html;charset="+this.character);
			chain.doFilter(req, resp);
			
		}
		
	
		
	}

	public void destroy() {
		// TODO Auto-generated method stub

	}

}
